package com.qf.controller;


import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.awt.print.Pageable;

@RestController
public class IndexController {

    @Autowired
    private RocketMQTemplate template;

    @RequestMapping("syncSend")
    public SendResult syncSend() {
        return template.syncSend("test-topic1:test-tag1","你好，迪迦奥特曼");
    }

    @RequestMapping("asyncSend")
    public void asyncSend(){
        template.asyncSend("test-topic2:test-tag2", "你好，迪迦奥特曼", new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                System.out.println(sendResult);
            }

            @Override
            public void onException(Throwable throwable) {
                throwable.printStackTrace();
            }
        });
    }

    @RequestMapping("onewaySend")
    public void onewaySend(){
        template.sendOneWay("test-topic4:test-tag4","你好，迪迦奥特曼");
    }

    @RequestMapping("delay")
    public String delay(){

        template.syncSend("test-topic5:test-tag5",MessageBuilder.withPayload("你好迪迦奥特曼").build(),2000,2);

        return "delay";
    }

}
